<?php

/**
 * this class provides functions for creating a searchbox
 * @author		ungerboeck simon <su@militaerversand.at>
 *
 */
class Searchbox {
    private $id = null;
    private $prompt = null;
    private $width = null;
    private $action = null;


    /************************************************************************
     ************************** PUBLIC FUNCTIONS ****************************
     ************************************************************************/

    /**
     * this functions set the id of the searchbox
     * @param         string         $id
     */
    public function __construct($id = null) {
        $this->id = $id;
    }


    /**
     * this creates the searchbox
     * @return         string         $output   
     */
    public function create() {
        $output = '<input class="easyui-searchbox" ';
        $output .= (isset($this->id) ? 'id="' . $this->id . '" ' : '');
        $output .= (isset($this->width) ? 'style="width:' . $this->width . 'px" ' : '');
        $output .= 'data-options="' . (isset($this->prompt) ? 'prompt:\'' . $this->prompt . '\', ' : '') . (isset($this->action) ? 'searcher:' . $this->action : '') . '" />';
        return $output;
    }
    
    
    /**
     * converts the obj to a string output
     * @return         string
     */
    public function __toString() {
        return $this->create();
    }


    /************************************************************************
     **************************** GETTER / SETTER ***************************
     ************************************************************************/


    public function setId($id) {
        $this->id = $id;
    }


    public function setPrompt($prompt) {
        $this->prompt = $prompt;
    }


    public function setWidth($width) {
        if (is_numeric($width))
            $this->width = $width;
    }


    public function setAction($action) {
        $this->action = $action;
    }


    public function getId() {
        return $this->id;
    }


    public function getPrompt() {
        return $this->prompt;
    }


    public function getWidth() {
        return $this->width;
    }


    public function getAction() {
        return $this->action;
    }

    /************************************************************************
     ************************** PRIVATE FUNCTIONS ***************************
     ************************************************************************/
}
